var dropDiv = document.getElementById('drop_div');

dropDiv.addEventListener('dragenter',function(){
    event.preventDefault();
},false);
dropDiv.addEventListener('dragover',function(){
    event.preventDefault();
},false);

dropDiv.addEventListener('drop', function(event){

    var fileReader = new FileReader();
    fileReader.onload = function(ev){
        var result = ev.target.result;
        document.body.innerHTML = '<pre>'+buildDratClass(result)+'</pre>';
    };
    fileReader.readAsText(event.dataTransfer.files[0]);
    event.preventDefault();
}, false);

function buildDratClass(css){
    var names = css.match(/(?<=\.).+(?=:before)/g);
    var values = css.match(/(?<="\\)e[0-9a-zA-Z]{3}(?=";)/g);
    var rawContent = "import 'package:flutter/widgets.dart';";
    rawContent += "\nclass IconFont{";
    rawContent += "\n\tstatic const String _family = 'iconfont';";
    rawContent += "\n\tIconFont._();";

    for(var i=0;i<names.length;i++){
        var name = names[i].replace(/-/g,'_');
        name = toLowerCamelCase(name);
        rawContent += "\n\tstatic const IconData "+name+" = IconData(0x"+values[i]+", fontFamily: _family);"
    }

    rawContent += "\n}";
    console.log(rawContent);

    return rawContent;
}